package glt.com.excel_handler;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.Panel;
import javax.swing.JInternalFrame;
import javax.swing.JScrollPane;
import java.awt.Font;
import javax.swing.JSeparator;
import javax.swing.SwingConstants;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.awt.event.ActionEvent;
import javax.swing.JFileChooser;
import java.awt.TextArea;
public class MainWin {

	private JFrame frame;
	JTextField textSourcePath;
	 JTextField textPngPath;
	 JTextField textVoltPng;
	 JTextField textVoltExtremPng;
	 JTextField textTempPng;
	 JTextField textTempExtremPng;
	 JTextField textVoltCol;
	 JTextField textVoltExtremCol;
	 JTextField textTempCol;
	 JTextField textTempExtremCol;
	 JTextField textVoltRange;
	 JTextField textTempRange;
	 JButton btnCopy;
	 JButton btnGen;
	private static MainWin window;
	TextArea textArea;
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					window = new MainWin();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public MainWin() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frame = new JFrame();
		frame.setBounds(100, 100, 800, 644);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(null);
		
		JLabel lblNewLabel = new JLabel("基本属性设置");
		lblNewLabel.setFont(new Font("宋体", Font.PLAIN, 16));
		lblNewLabel.setBounds(57, 20, 111, 26);
		frame.getContentPane().add(lblNewLabel);
		
		JSeparator separator = new JSeparator();
		separator.setBounds(157, 33, 617, 13);
		frame.getContentPane().add(separator);
		
		JSeparator separator_1 = new JSeparator();
		separator_1.setBounds(10, 33, 40, 13);
		frame.getContentPane().add(separator_1);
		
		JSeparator separator_1_1 = new JSeparator();
		separator_1_1.setOrientation(SwingConstants.VERTICAL);
		separator_1_1.setBounds(10, 33, 8, 142);
		frame.getContentPane().add(separator_1_1);
		
		JLabel lblNewLabel_1 = new JLabel("源数据路径");
		lblNewLabel_1.setFont(new Font("宋体", Font.PLAIN, 14));
		lblNewLabel_1.setBounds(28, 56, 111, 26);
		frame.getContentPane().add(lblNewLabel_1);
		
		JLabel lblNewLabel_1_1 = new JLabel("图片路径");
		lblNewLabel_1_1.setFont(new Font("宋体", Font.PLAIN, 14));
		lblNewLabel_1_1.setBounds(403, 56, 70, 26);
		frame.getContentPane().add(lblNewLabel_1_1);
		
		textSourcePath = new JTextField();
		textSourcePath.setBounds(103, 59, 223, 21);
		frame.getContentPane().add(textSourcePath);
		textSourcePath.setColumns(10);
		
		JButton btnNewButton = new JButton("选择");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				JFileChooser chooser = new JFileChooser();
				chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
				int option = chooser.showOpenDialog(frame);
				if (option == JFileChooser.APPROVE_OPTION) {
					File file = chooser.getSelectedFile();
					textSourcePath.setText(file.getAbsolutePath());
				}
				
			}
		});
		btnNewButton.setBounds(336, 58, 63, 23);
		frame.getContentPane().add(btnNewButton);
		
		textPngPath = new JTextField();
		textPngPath.setColumns(10);
		textPngPath.setBounds(466, 56, 223, 21);
		frame.getContentPane().add(textPngPath);
		
		JButton btnNewButton_1 = new JButton("选择");
		btnNewButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				JFileChooser chooser = new JFileChooser();
				chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
				int option = chooser.showOpenDialog(frame);
				if (option == JFileChooser.APPROVE_OPTION) {
					File file = chooser.getSelectedFile();
					textPngPath.setText(file.getAbsolutePath());
				}
			}
		});
		btnNewButton_1.setBounds(699, 56, 64, 23);
		frame.getContentPane().add(btnNewButton_1);
		
		JLabel lblNewLabel_1_2 = new JLabel("电压图片");
		lblNewLabel_1_2.setFont(new Font("宋体", Font.PLAIN, 14));
		lblNewLabel_1_2.setBounds(38, 92, 111, 26);
		frame.getContentPane().add(lblNewLabel_1_2);
		
		textVoltPng = new JTextField("陕煤{0}{1} {2}号-{3}号电芯电压");
		textVoltPng.setColumns(10);
		textVoltPng.setBounds(103, 95, 223, 21);
		textVoltPng.setCaretPosition(0);
		frame.getContentPane().add(textVoltPng);
		
		JLabel lblNewLabel_1_2_1 = new JLabel("电压极值图片");
		lblNewLabel_1_2_1.setFont(new Font("宋体", Font.PLAIN, 14));
		lblNewLabel_1_2_1.setBounds(378, 92, 111, 26);
		frame.getContentPane().add(lblNewLabel_1_2_1);
		
		textVoltExtremPng = new JTextField("陕煤{0}{1} 电压最大值、最小值、平均值以及{2}号电芯电压");
		textVoltExtremPng.setColumns(10);
		textVoltExtremPng.setBounds(466, 93, 223, 21);
		textVoltExtremPng.setCaretPosition(0);
		frame.getContentPane().add(textVoltExtremPng);
		
		JLabel lblNewLabel_1_2_2 = new JLabel("温度图片");
		lblNewLabel_1_2_2.setFont(new Font("宋体", Font.PLAIN, 14));
		lblNewLabel_1_2_2.setBounds(38, 128, 111, 26);
		frame.getContentPane().add(lblNewLabel_1_2_2);
		
		textTempPng = new JTextField("陕煤{0}{1} {2}号-{3}号温度点");
		textTempPng.setColumns(10);
		textTempPng.setBounds(103, 131, 223, 21);
		textTempPng.setCaretPosition(0);
		frame.getContentPane().add(textTempPng);
		
		JLabel lblNewLabel_1_2_1_1 = new JLabel("温度极值图片");
		lblNewLabel_1_2_1_1.setFont(new Font("宋体", Font.PLAIN, 14));
		lblNewLabel_1_2_1_1.setBounds(378, 128, 111, 26);
		frame.getContentPane().add(lblNewLabel_1_2_1_1);
		
		textTempExtremPng = new JTextField("陕煤{0}{1} 温度最大值、最小值、平均值以及{2}号电芯温度");
		textTempExtremPng.setColumns(10);
		textTempExtremPng.setBounds(466, 129, 223, 21);
		textTempExtremPng.setCaretPosition(0);
		frame.getContentPane().add(textTempExtremPng);
		
		JSeparator separator_1_1_1 = new JSeparator();
		separator_1_1_1.setOrientation(SwingConstants.VERTICAL);
		separator_1_1_1.setBounds(773, 33, 8, 142);
		frame.getContentPane().add(separator_1_1_1);
		
		JSeparator separator_2 = new JSeparator();
		separator_2.setBounds(10, 174, 764, 13);
		frame.getContentPane().add(separator_2);
		
		JLabel lblNewLabel_2 = new JLabel("列属性设置");
		lblNewLabel_2.setFont(new Font("宋体", Font.PLAIN, 16));
		lblNewLabel_2.setBounds(57, 193, 111, 26);
		frame.getContentPane().add(lblNewLabel_2);
		
		JSeparator separator_1_2 = new JSeparator();
		separator_1_2.setBounds(10, 206, 40, 13);
		frame.getContentPane().add(separator_1_2);
		
		JSeparator separator_3 = new JSeparator();
		separator_3.setBounds(157, 206, 617, 13);
		frame.getContentPane().add(separator_3);
		
		JSeparator separator_1_1_2 = new JSeparator();
		separator_1_1_2.setOrientation(SwingConstants.VERTICAL);
		separator_1_1_2.setBounds(10, 205, 8, 142);
		frame.getContentPane().add(separator_1_1_2);
		
		JLabel lblNewLabel_1_2_3 = new JLabel("电压列");
		lblNewLabel_1_2_3.setFont(new Font("宋体", Font.PLAIN, 14));
		lblNewLabel_1_2_3.setBounds(28, 219, 111, 26);
		frame.getContentPane().add(lblNewLabel_1_2_3);
		
		textVoltCol = new JTextField("0");
		textVoltCol.setColumns(10);
		textVoltCol.setBounds(79, 222, 98, 21);
		frame.getContentPane().add(textVoltCol);
		
		JLabel lblNewLabel_1_2_1_2 = new JLabel("复制到电压极值列");
		lblNewLabel_1_2_1_2.setFont(new Font("宋体", Font.PLAIN, 14));
		lblNewLabel_1_2_1_2.setBounds(187, 219, 123, 26);
		frame.getContentPane().add(lblNewLabel_1_2_1_2);
		
		textVoltExtremCol = new JTextField("0");
		textVoltExtremCol.setColumns(10);
		textVoltExtremCol.setBounds(311, 222, 148, 21);
		frame.getContentPane().add(textVoltExtremCol);
		
		JLabel lblNewLabel_1_2_3_1 = new JLabel("温度列");
		lblNewLabel_1_2_3_1.setFont(new Font("宋体", Font.PLAIN, 14));
		lblNewLabel_1_2_3_1.setBounds(28, 257, 111, 26);
		frame.getContentPane().add(lblNewLabel_1_2_3_1);
		
		textTempCol = new JTextField("0");
		textTempCol.setColumns(10);
		textTempCol.setBounds(79, 260, 98, 21);
		frame.getContentPane().add(textTempCol);
		
		JLabel lblNewLabel_1_2_1_2_1 = new JLabel("复制到温度极值列");
		lblNewLabel_1_2_1_2_1.setFont(new Font("宋体", Font.PLAIN, 14));
		lblNewLabel_1_2_1_2_1.setBounds(187, 257, 178, 26);
		frame.getContentPane().add(lblNewLabel_1_2_1_2_1);
		
		textTempExtremCol = new JTextField("0");
		textTempExtremCol.setColumns(10);
		textTempExtremCol.setBounds(311, 260, 148, 21);
		frame.getContentPane().add(textTempExtremCol);
		
		 btnCopy = new JButton("复制列");
		btnCopy.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				DataHandler dHandler = new DataHandler(window);
				try {
					dHandler.handleFile(window);
				} catch (NumberFormatException | IOException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		});
		btnCopy.setBounds(261, 300, 87, 23);
		frame.getContentPane().add(btnCopy);
		
		 btnGen = new JButton("生成图片");
		btnGen.setBounds(375, 300, 98, 23);
		btnGen.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				//DataHandler dHandler = new DataHandler(window);
				try {
					Thread t = new Thread( new DataHandler(window ) );
					t.start();
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
			}
			
		});
		frame.getContentPane().add(btnGen);
		
		 textArea = new TextArea();
		textArea.setBounds(10, 329, 764, 254);
		frame.getContentPane().add(textArea);
		
		JSeparator separator_1_1_2_1 = new JSeparator();
		separator_1_1_2_1.setOrientation(SwingConstants.VERTICAL);
		separator_1_1_2_1.setBounds(773, 205, 8, 142);
		frame.getContentPane().add(separator_1_1_2_1);
		
		JLabel lblNewLabel_1_2_1_2_2 = new JLabel("电压列范围");
		lblNewLabel_1_2_1_2_2.setFont(new Font("宋体", Font.PLAIN, 14));
		lblNewLabel_1_2_1_2_2.setBounds(469, 219, 111, 26);
		frame.getContentPane().add(lblNewLabel_1_2_1_2_2);
		
		textVoltRange = new JTextField();
		textVoltRange.setColumns(10);
		textVoltRange.setBounds(547, 222, 148, 21);
		frame.getContentPane().add(textVoltRange);
		
		JLabel lblNewLabel_1_2_1_2_2_1 = new JLabel("温度列范围");
		lblNewLabel_1_2_1_2_2_1.setFont(new Font("宋体", Font.PLAIN, 14));
		lblNewLabel_1_2_1_2_2_1.setBounds(469, 257, 111, 26);
		frame.getContentPane().add(lblNewLabel_1_2_1_2_2_1);
		
		textTempRange = new JTextField();
		textTempRange.setColumns(10);
		textTempRange.setBounds(547, 260, 148, 21);
		frame.getContentPane().add(textTempRange);
	}
}
